package org.cars.gracefulController.controller;

import org.cars.gracefulController.models.business.ProductInfoVo;
import org.cars.gracefulController.models.exception.APIException;
import org.cars.gracefulController.models.response.ResultVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author caoqianfan
 * @date 2024/5/21 上午9:47
 */
@RestController
@RequestMapping("/product/product-info")
public class ProductInfoController {

//    @Resource
//    ProductInfoService productInfoService;

    @GetMapping("/findById")
    public String findById(Integer id) {
        if(Math.random() > 0.3){
            return id + " : 小王";
        }
        throw new APIException("id获取异常");
    }

    @PostMapping("/list")
    public List<String> findList() {
        List<String> aList = new ArrayList<>();
        aList.add("小王");
        aList.add("小李");
        return aList;
    }

    @PostMapping("/findByVo")
    public ResultVo findByVo(@Validated ProductInfoVo vo) {
//        ProductInfo productInfo = new ProductInfo();
//        BeanUtils.copyProperties(vo, productInfo);
        return new ResultVo(vo);
    }
}